<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <div id="app">
      商品单价为：<input type="text" v-model="price" /> 购买数量为：<input
        type="text"
        v-model="num"
      />
      <br />
      总价为：<span>{{res}}</span>
    </div>
    <script src="lib/vue.js"></script>
    <script>
      var vm = new Vue({
        el: "#app",
        data: {
          price: 0,
          num: 0,
        },
        computed: {
          res() {
            return this.price * this.num;
            // 返回的总价是单价*数量
          },
        },
      });
    </script>
  </body>
</html>
